package com.lyj.system.controller.sysUser;

import com.lyj.common.core.constants.HttpConstants;
import com.lyj.common.core.controller.BaseController;
import com.lyj.common.core.domain.R;
import com.lyj.common.core.domain.vo.LoginUserVO;
import com.lyj.system.domain.sysUser.dto.LoginDTO;
import com.lyj.system.domain.sysUser.dto.SysUserSaveDTO;
import com.lyj.system.service.sysUser.SysUserService;
import jakarta.annotation.Resource;

import org.springframework.web.bind.annotation.*;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: LIUYANJIAO
 * Date: 2025-08-12
 * Time: 23:51
 */
@RestController
@RequestMapping("/sysUser")
public class SysUserController extends BaseController {
    @Resource(name = "sysUserServiceImpl")
    private SysUserService sysUserService;

    /**
     *管理员登录
     * @param loginDTO
     * @return
     */
    @PostMapping("/login")
    public R<String> login(@RequestBody LoginDTO loginDTO){
        return sysUserService.login(loginDTO.getUserAccount(),loginDTO.getPassword());
    }

    /**
     * 退出登录
     * @param token
     * @return
     */
    @DeleteMapping("/logout")
    public R<Void> logout(@RequestHeader(HttpConstants.AUTHENTICATION) String token){
         return toR(sysUserService.logout(token));
    }

    /**
     * 获得用户详情
     * @param token
     * @return
     */
    @GetMapping("/info")
    public R<LoginUserVO> info(@RequestHeader(HttpConstants.AUTHENTICATION) String token){
        return sysUserService.info(token);
    }

    //新增管理员
    @PostMapping("/add")
    public R<Void> add(@RequestBody SysUserSaveDTO sysUserSaveDTO){
        return toR(sysUserService.add(sysUserSaveDTO));
    }
}
